// 
//  watchURL.js
//  firefox
//  
//  Created by Zak on 2008-07-14.
//  Copyright 2008 Ant.com. All rights reserved.
// 

var AntUrlListener =
{
    QueryInterface: function(aIID)
    {
        if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
                aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
                aIID.equals(Components.interfaces.nsISupports))
            return this;
        throw Components.results.NS_NOINTERFACE;
    },

    onLocationChange: function(aProgress, aRequest, aURI)
    {
        AntWatchUrl.notify(aURI);
    },

    onStateChange: function() {},
    onProgressChange: function() {},
    onStatusChange: function() {},
    onSecurityChange: function() {},
    onLinkIconAvailable: function() {}
};

var AntWatchUrl =
{
    init: function ()
    {
        window.addEventListener("load", function() { AntWatchUrl.start() }, false);
        window.addEventListener("unload", function() { AntWatchUrl.stop() }, false);
    },
    
    start: function ()
    {
        gBrowser.addProgressListener(AntUrlListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
    },

    stop: function ()
    {
        gBrowser.removeProgressListener(AntUrlListener);
    },


    notify: function (aURI)
    {
        if (aURI == null)
            aURI = {spec: "about:blank"};
        AntRank.updateRank(aURI);
	AntFlvUi.updateContent(aURI.spec);
	AntFlvUi.updateDownloadButton();
	if (aURI.spec == "chrome://antbar/content/player/player.xul")
	{
		AntFlvUi.togglePanel(false);
		AntFlvUi.disableMovieListButton(false);
	}
	else
	{
	    AntFlvUi.disableMovieListButton(true);
	}
    }
};
